//
//  MTClubApi.swift
//  MT
//
//  Created by ooops on 2019/12/25.
//  Copyright © 2019 张强. All rights reserved.
//

import Foundation
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MTClubApi {
    /// 创建俱乐部
    case createClub(_ requestParam: [String : Any])
    /// 查询俱乐部信息
    case getClubInfo(_ requestPatam: [String : Any])
    /// 编辑俱乐部
    case editClub(_ requestParam: [String : Any])
    /// 查询土豪榜
    case queryRich(_ requestParam: [String : Any])
    /// 查询最新俱乐部
    case queryLester(_ requestParam: [String : Any])
    /// 创建俱乐部活动
    case createClubActivities(_ requestParam: [String : Any])
    /// 编辑俱乐部活动
    case editClubActivity(_ requestParam: [String : Any])
    /// 查询进行中的活动
    case queryEnrollRun(_ requestParam: [String : Any])
    /// 查询已经结束的活动
    case queryEnrollEnd(_ requestParam: [String : Any])
    /// 查询俱乐部活动所需钻石
    case createActivityConsumeMoney
    /// 查询俱乐部所需钻石
    case createClubConsumeMoney
    /// 查询俱乐部活动详情
    case queryActivityInfo(_ requestParam: [String : Any])
    /// 查询俱乐部活动
    case queryClubActivities(_ requestParam: [String : Any])
    /// 操作俱乐部成员给后台的回传接口
    case operateClubUser(_ requestParam: [String : Any])
    /// 操作俱乐部活动成员给后台的回传接口
    case operateClubActivityUser(_ requestParam: [String : Any])
    /// 查询创建俱乐部 / 俱乐部活动 / 用户余额
    case config
    /// 活动报名
    case enroll(_ requestParam: [String : Any])
}

// MARK: ------------------  ----------------------
extension MTClubApi: MTTargetType {
    /// 请求头
    var headers: [String : String]? {
        //return ["Access-Token": "I6w6XbQSWNQIsnB9zKFbtV7b"]
        return ["Access-Token": UserDefaults.MTUserCenter.token.storedString ?? ""]
    }

    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .createClub(_):
            return "/club/add"
        case .getClubInfo(_):
            return "/club/getById"
        case .editClub(_):
            return "/club/edit"
        case .queryRich(_):
            return "/club/queryRich"
        case .queryLester(_):
            return "/club/queryNew"
        case .createClubActivities(_):
            return "/clubActivity/create"
        case .queryEnrollRun(_):
            return "/clubActivity/queryEnrollRun"
        case .queryEnrollEnd(_):
            return "/clubActivity/queryEnrollEnd"
        case .createActivityConsumeMoney:
            return "clubMoney/createActivityConsumeMoney"
        case .createClubConsumeMoney:
            return "clubMoney/createClubConsumeMoney"
        case .queryActivityInfo(_):
            return "/clubActivity/queryActivityInfo"
        case .queryClubActivities(_):
            return "/clubActivity/queryActivityList"
        case .operateClubUser(_):
            return "clubUser/operate"
        case .operateClubActivityUser(_):
            return "/clubActivityUser/operate"
        case .config:
            return "/user/config"
        case .enroll(_):
            return "clubActivityUser/enroll"
        case .editClubActivity(_):
            return "/clubActivity/edit"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        switch self {
        case let .createClub(requestParam):
            return requestParam
        case let .getClubInfo(requestParam):
            return requestParam
        case let .editClub(requestParam):
            return requestParam
        case let .queryRich(requestParam):
            return requestParam
        case let .queryLester(requestParam):
        return requestParam
        case let .createClubActivities(requestParam):
            return requestParam
        case let .queryEnrollRun(requestParam):
            return requestParam
        case let .queryEnrollEnd(requestParam):
            return requestParam
        case .createActivityConsumeMoney, .createClubConsumeMoney, .config:
            return nil
        case let .queryActivityInfo(requestParma):
            return requestParma
        case let .queryClubActivities(requestParam):
            return requestParam
        case let .operateClubUser(requestParam):
            return requestParam
        case let .operateClubActivityUser(requestParam):
            return requestParam
        case let .enroll(requestParam):
            return requestParam
        case let .editClubActivity(requestParam):
            return requestParam
        }
    }
    
}
